package com.example.administrator.mvptest.view.presenter;

import com.example.administrator.mvptest.view.biz.ZhihuDailyBiz;
import com.example.administrator.mvptest.view.databeans.ZhihuStory;
import com.example.administrator.mvptest.view.utils.OnEventLister;
import com.example.administrator.mvptest.view.view.IViewBind.IMainActivity;

import java.util.ArrayList;

/**
 * Created by Administrator on 2016-11-24.
 */
public class MainPresenter {
    private IMainActivity mIMainActivity;
    private ZhihuDailyBiz mDailyBiz;
    public MainPresenter(IMainActivity IMainActivity)
    {
        // 绑定view对象
        mIMainActivity=IMainActivity;
        //绑定获取业务实现对象
        mDailyBiz=new ZhihuDailyBiz();
    }
    //普通封装的okhttp进行网络请求
    public  void  loadData()
    {
        //显示进度条TODO
        mDailyBiz.getStoryData("new/latest", new OnEventLister<ArrayList<ZhihuStory>>() {
            @Override
            public void onSuccess(ArrayList<ZhihuStory> response) {
                //隐藏进度条TODO

                mIMainActivity.getDataSuccess(response);
            }

            @Override
            public void onFial(String errCode, String errMsg) {
                //隐藏进度条TODO
                mIMainActivity.getDataFail(errCode,errMsg);
            }
        });
    }
    public  void  loadDataByRetrofit()
    {

        mDailyBiz.getStoryDataByRetrofit(new OnEventLister<ArrayList<ZhihuStory>>() {
            @Override
            public void onSuccess(ArrayList<ZhihuStory> response) {
                mIMainActivity.getDataSuccess(response);
            }

            @Override
            public void onFial(String errCode, String errMsg) {
                mIMainActivity.getDataFail(errCode,errMsg);
            }
        });
    }
}
